package com.example.wxminiprogram.service.GoodsServiceImpl;

import com.example.wxminiprogram.mapper.ClassMapper;
import com.example.wxminiprogram.pojo.GoodsClass;
import com.example.wxminiprogram.service.ClassService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class ClassServiceImpl implements ClassService {
    @Autowired
    ClassMapper classMapper;
    @Override
    public String getL2NameById(Integer id){
        return this.classMapper.getL2NameById(id);
    }
    @Override
    public List<GoodsClass> getL1(){

        return this.classMapper.getL1();
    }
    @Override
    public List<GoodsClass> getL2(){
        return this.classMapper.getL2();
    }
    @Override
    public List<GoodsClass> getL2ByL1(Integer super_id){
        return this.classMapper.getL2BySuperId(super_id);
    }
    @Override
    public List<GoodsClass> getL1AndL2(){
        List<GoodsClass> goodsClassList = this.getL1();
        goodsClassList.forEach(e->{
            e.setChildren(this.getL2ByL1(e.getId()));
        });
        return goodsClassList;
    }
}
